Open Map Views
Count of the number of times a map was viewed using the Open Maps Viewer https://open.canada.ca/data/en/dataset/2916fad5-ebcc-4c86-b0f3-4f619b29f412/resource/15eeafa2-c331-44e7-b37f-d0d54a51d2eb
Maritime’s Data
Show the code
pubs <- read.csv ("MARScienceDataPublications(Publications).csv" ) |>
mutate (uuid = basename (Open.Data.Link),
nchar = nchar (uuid)) |>
filter (nchar== 36 )
req <- request ("https://open.canada.ca/data/en/api/action/datastore_search" )
data <- data.frame ()
for (id in pubs$ uuid){
result <- req |>
# req_headers(Authorization = API_TOKEN) %>%
req_body_json (list (
resource_id = '15eeafa2-c331-44e7-b37f-d0d54a51d2eb' ,
limit = 50 ,
q = id)) |>
req_perform () |>
resp_body_json ()
newdata <- result$ result$ records |>
lapply (as.data.frame) |>
bind_rows () |>
mutate (uuid = id)
if (! id %in% data$ uuid){
data <- bind_rows (data,
newdata)
}
}
sumdata <- data |>
group_by (title_en) |>
reframe (totalviews= sum (pageviews))
(ggplot (sumdata,aes (x = title_en,y = totalviews)) +
geom_col ()+
coord_flip ()+
theme_classic ()+
theme (axis.text.y= element_blank (),
axis.ticks.y= element_blank ())+
scale_y_continuous (expand = expansion (mult = c (0 ,0.1 ))))|>
ggplotly ()
Maritime’s time series
Show the code
sumdata <- data |>
mutate (Source= case_when (grepl ("NETForce" ,title_en) ~ "NETForce" ,
grepl ("CAN-EWLAT" ,title_en) ~ "CAN-EWLAT" ,
.default = "All other data" ),
Source= factor (Source,levels= c ("NETForce" ,
"CAN-EWLAT" ,
"All other data" ))) |>
group_by (year,month,Source) |>
reframe (` Total Views per Month ` = sum (pageviews))%>%
mutate (date = as.Date (paste (year, month, "01" , sep = "-" )))
ggplot (sumdata,aes (x = date,y = ` Total Views per Month ` ,fill = Source)) +
geom_area (position = 'stack' )+
theme_classic ()+
theme (axis.text.x = element_text (angle = 90 , vjust = 0.5 , hjust= 1 ))+
scale_x_date (date_break = 'month' ,
expand = expansion (mult = c (0 ,0 )),
date_labels = "%m-%Y" )+
scale_y_continuous (expand = expansion (mult = c (0 ,0 )))+
labs (x= "" )
All Data
Show the code
req <- request ("https://open.canada.ca/data/en/api/action/datastore_search_sql" )
result <- req|>
# req_headers(Authorization = API_TOKEN) |>
req_body_json (list (
sql = "SELECT * FROM \" 15eeafa2-c331-44e7-b37f-d0d54a51d2eb \" WHERE owner_org LIKE 'dfo-mpo'" )) |>
req_perform () |>
resp_body_json ()
data <- result$ result$ records |>
lapply (as.data.frame) |>
bind_rows () |>
mutate (Region= if_else (id %in% pubs$ uuid,
"Maritimes" ,
"Other" ))
sumdata <- data |>
group_by (title_en,Region) |>
reframe (totalviews= sum (as.numeric (pageviews)))
(ggplot (sumdata,
aes (x = title_en,y = totalviews, fill = Region)) +
geom_col ()+
coord_flip ()+
theme_classic ()+
theme (axis.text.y= element_blank (),
axis.ticks.y= element_blank ())+
scale_y_continuous (expand = expansion (mult = c (0 ,0.1 ))))|>
ggplotly ()
Number of visits
https://open.canada.ca/data/en/dataset/2916fad5-ebcc-4c86-b0f3-4f619b29f412/resource/c14ba36b-0af5-4c59-a5fd-26ca6a1ef6db
Show the code
req <- request ("https://open.canada.ca/data/en/api/action/datastore_search_sql" )
result <- req|>
req_body_json (list (
sql = "SELECT * FROM \" c14ba36b-0af5-4c59-a5fd-26ca6a1ef6db \" WHERE department LIKE 'Fisheries and Oceans Canada'" )) |>
req_perform () |>
resp_body_json ()
data <- result$ result$ records |>
lapply (as.data.frame) |>
bind_rows () |>
mutate (Region= if_else (id %in% pubs$ uuid,
"Maritimes" ,
"Other" ))
sumdata <- data |>
group_by (title,Region) |>
reframe (totalvisits= sum (as.numeric (visits_visites)))
(ggplot (sumdata |> filter (Region == "Maritimes" ),
aes (x = title,y = totalvisits)) +
geom_col ()+
coord_flip ()+
theme_classic ()+
theme (axis.text.y= element_blank (),
axis.ticks.y= element_blank ())+
scale_y_continuous (expand = expansion (mult = c (0 ,0.1 )))) |>
ggplotly ()
Number of downloads
https://open.canada.ca/data/en/dataset/2916fad5-ebcc-4c86-b0f3-4f619b29f412/resource/4ebc050f-6c3c-4dfd-817e-875b2caf3ec6
Show the code
req <- request ("https://open.canada.ca/data/en/api/action/datastore_search_sql" )
result <- req|>
req_body_json (list (
sql = "SELECT * FROM \" 4ebc050f-6c3c-4dfd-817e-875b2caf3ec6 \" WHERE department LIKE 'Fisheries and Oceans Canada'" )) |>
req_perform () |>
resp_body_json ()
data <- result$ result$ records |>
lapply (as.data.frame) |>
bind_rows () |>
mutate (Region= if_else (id %in% pubs$ uuid,
"Maritimes" ,
"Other" ))
sumdata <- data |>
group_by (title,Region) |>
reframe (totaldownloads= sum (as.numeric (downloads_telechargements)))
(ggplot (sumdata |> filter (Region == "Maritimes" ),
aes (x = title,y = totaldownloads)) +
geom_col ()+
coord_flip ()+
theme_classic ()+
theme (axis.text.y= element_blank (),
axis.ticks.y= element_blank ())+
scale_y_continuous (expand = expansion (mult = c (0 ,0.1 )))) |>
ggplotly ()